package main
import (
	"fmt" 
	"os" 
	"io" 
	"bufio"
)

func copyFile(distName string,srcName string)(written int64,err error){
	srcFile,err :=os.Open(srcName)

	if err!=nil{
		fmt.Println("open file err=",err)
		return
	}
	defer srcFile.Close()

	reader:=bufio.NewReader(srcFile)

	distFile,err :=os.OpenFile(distName,os.O_WRONLY|os.O_CREATE,0666)
	if err!=nil {
		fmt.Println("open file err",err)
		return
	}

	writer := bufio.NewWriter(distFile)
	defer distFile.Close()
	return io.Copy(writer,reader)


}

func main(){
	filePath1:="E:\\ProgramData\\GoWorkSpace\\src\\go_code\\project03/day1/a.png"
	filePath2:="E:\\ProgramData\\GoWorkSpace\\src\\go_code\\project03/day1/b.png"

	_,err := copyFile(filePath2,filePath1)
	if err ==nil{
		fmt.Println("copy finished")
	}else {
		fmt.Println("copy erro=",err)
	}

	
}